using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;

public class QuestManager : singleTon<QuestManager>
{
    [Serializable]
    public class QuestTask
    {
        public QuestData_SO QuestData;

        public bool IsStarted
        {
            get { return QuestData.isStarted;}
            set { QuestData.isStarted = value; }
        }
        public bool IsComplete
        {
            get { return QuestData.isComplete;}
            set { QuestData.isComplete = value; }
        }
        public bool IsFinished
        {
            get { return QuestData.isFinished;}
            set { QuestData.isFinished = value; }
        }
    }
    
    protected override void Awake()
    {
        base.Awake();
        DontDestroyOnLoad(this);
    }
    
    


    public List<QuestTask> QuestTasks = new List<QuestTask>();


    public void updateQuestProgress(string requireName, int amount)
    {
        foreach (var task in QuestTasks)
        {
            var matchTask = task.QuestData.questRequires.Find(r => r.requiretName == requireName);
            if (matchTask != null)
            {
                matchTask.currentAmount += amount;
            }
            task.QuestData.CheackQuestProgress();
        }
    }
    public bool HaveQuest(QuestData_SO data)
    {
        if (data != null)
        {
            return QuestTasks.Any(q => q.QuestData.questName == data.questName);
        }
        else return false;
    }

    public QuestTask GetTask(QuestData_SO data)
    {
        if (data != null)
        {
            return QuestTasks.Find(q => q.QuestData.questName == data.questName);
        }
        else
        {
            return null;
        }
    }
}
